<?php
require_once 'Zend/Controller/Action.php';
require_once 'Usuarios/ResourcesProvider.class.php';
require_once 'Usuarios/RolesProvider.class.php';

class GestionRoles_AltaRolesController extends Zend_Controller_Action {
	public function init() {
		$registry = Zend_Registry :: getInstance();
		$this->smarty = $registry->smarty;
		$this->smarty->assign('baseUrl', $this->getRequest()->getBaseUrl());
		$this->smarty->assign('moduleName', $this->getRequest()->getModuleName());
		$this->smarty->assign('controllerName', $this->getRequest()->getControllerName());
		$this->smarty->assign('actionName', $this->getRequest()->getActionName());
		$this->smarty->assign('subtitulo', 'Alta de Roles');
	}

	public function indexAction() {
		if ($this->getRequest()->isPost()) {
			$registry = Zend_Registry :: getInstance();
			try {
				RolesProvider :: saveRol($this->getRequest()->getParam('nombre'), $this->getRequest()->getParam('recursos'));
				$this->smarty->assign('mensajeCorrecto', 'El Nivel ' . $this->getRequest()->getParam('nombre') . ' ha sido de alta satisfactoriamente.');
			} catch (Exception $e) {
				$this->smarty->assign('mensajeError', 'Error : ' . $e->getMessage());
			}
		}
		$this->smarty->assign('resources', ResourcesProvider :: getResourcesPairs());
		$this->smarty->displayInMasterPage('gestionroles_altaroles_index.tpl', 'MasterPage.tpl');
	}
}
?>
